<?php
class KController {

    public $defaultController = 'Index';
    public $defaultAction = 'Index';
    public $controller;
    public $action;
    public $_data;

    const SUFFIX = '.php';

    public function __construct($controller, $action) {
        if ($controller) {
            $this->controller = $controller;
        } else {
            $this->controller = $this->defaultController;
        }
        if ($action) {
            $this->action = $action;
        } else {
            $this->action = $this->defaultAction;
        }
    }

    public function render($tpl = NULL) {
        if (!$tpl) {
            $tpl = lcfirst($this->action);
        }
        ob_start();
        $data = $this->_data;
        include VIEW_PATH . DIRECTORY_SEPARATOR . $this->controller . DIRECTORY_SEPARATOR . $tpl . self::SUFFIX;
        ob_end_flush();
        exit;
    }

    public function fetch($var, $value) {
        $this->_data[$var] = $value;
    }

}
?>